import {
	ref
} from "vue";
export function useNavbar () {
	const statusBarHeight = ref(20) // 状态栏高度
	const sysStatusBarHeight = ref(20) //系统状态栏高度
	const navBarHeight = ref(40) // 导航栏高度(标题栏高度)
	const navHeight = ref(60) // 总体高度
	const tabbarHeight = ref(60) //菜单栏高度
	const bottomHeight = ref(0) //底部安全区域高度
	const pageHeight = ref(800) //页面高度
	const pageCustomHeight = ref(800) //页面高度，隐藏导航栏
	const isLandscape = ref(false) //当前页面是否横屏，默认竖屏
	// 获取导航栏高度
	function getNabbarHeight () {
		// 获取系统信息
		const systemInfo = wx.getWindowInfo();
		// 状态栏高度
		statusBarHeight.value = systemInfo.statusBarHeight || 20;
		sysStatusBarHeight.value = systemInfo.statusBarHeight || 20;
		// #ifdef MP-WEIXIN
		// 获取微信胶囊的位置信息 width,height,top,right,left,bottom
		const custom = wx.getMenuButtonBoundingClientRect();
		// 获取当前设备的方向
		const systemSetting = wx.getSystemSetting();
		const deviceOrientation = systemSetting.deviceOrientation;
		if (deviceOrientation == 'landscape') {
			// 横屏 landscape
			isLandscape.value = true;
			statusBarHeight.value = 0;
		} else {
			// 竖屏 portrait
			isLandscape.value = false;
		}
		// 导航栏高度(标题栏高度) = 胶囊高度 + (顶部距离 - 状态栏高度) * 2
		navBarHeight.value = custom.height + (custom.top - statusBarHeight.value) * 2;
		// 底部安全区域高度
		bottomHeight.value = systemInfo.screenHeight - systemInfo.safeArea.bottom;
		// 菜单栏高度
		const pages = getCurrentPages();
		const currentPage = pages[pages.length - 1].route;
		if (currentPage == "pages/index/index") {
			tabbarHeight.value = 60 + bottomHeight.value;
		} else {
			tabbarHeight.value = 0;
		}
		// 总体高度 = 状态栏高度 + 导航栏高度
		navHeight.value = navBarHeight.value + statusBarHeight.value;
		// 页面高度 = windowHeight - navHeight - tabbarHeight
		pageHeight.value = systemInfo.windowHeight - navHeight.value - tabbarHeight.value;
		pageCustomHeight.value = systemInfo.windowHeight - tabbarHeight.value;
		// #endif
	}
	getNabbarHeight()
	return {
		statusBarHeight: statusBarHeight.value + 'px',
		navBarHeight: navBarHeight.value + 'px',
		navHeight: navHeight.value + 'px',
		pageHeight: pageHeight.value + 'px',
		pageCustomHeight: pageCustomHeight.value + 'px',
		sysStatusBarHeight: sysStatusBarHeight.value + 'px',
		tabbarHeight: tabbarHeight.value + 'px',
		bottomHeight: bottomHeight.value + 'px',
		isLandscape: isLandscape,
	}
}
// 字典
export function useDict () {
	const warnLevel = ref({
		0: "紧急告警",
		1: "严重告警",
		2: "普通告警"
	});
	const warnType = ref({
		0: "温度告警",
		1: "运管告警",
		2: "制冷告警",
		3: "设备告警"
	});
	const pushType = ref({
		0: "温度告警",
		1: "运管告警",
		2: "制冷告警",
		3: "设备告警"
	});
	return {
		warnLevel,
		warnType,
		pushType
	}
}